﻿package com.hodgedev.net.drupal 
{
	import flash.events.EventDispatcher;
	import flash.net.NetConnection;
	/**
	 * Abstract class to be extended by a service subclass
	 * such as System.as.
	 * @author Brian Hodge (brian@hodgedev.com)
	 */
	public class Service extends EventDispatcher implements IService
	{
		protected var _sessid:String;
		protected var _services:Services;
		protected var _nc:NetConnection;
		
		protected function _checkServiceConnected():Boolean
		{
			if (!_services.connected)
			{
				_services.addEventListener(ServicesEvent.SYSTEM_CONNECTED, onConnect);
				_services.connect(_services.gateway);
			}
			return _services.connected;
		}
		public function onConnect(e:ServicesEvent):void
		{
			throw(new Error("protected function _onConnect must be overriden."));
		}
		public function closeConnection():void
		{
			_services.close();
		}
	}
}